Hello and welcome back to our costs.
So in this session we learn about boolean indexing of some higher res.
So what does it mean.
So let's assume we have an umpire Ray with many elements and we want to check element y's if the element
meets a certain conditions of like sample.
You want to check if each element is greater than five or not.
And with NUM PI we can do this in a vector rest fashion.
So we do not need to write for loops or if elif and US statements.
So let's start to code.
Let's.
Important umpire.
And then we create an umpire Ray from 1 to 10 and then we check element twice.
So we have a if a is greater than five.
So we check for each element here.
If the element is greater than five and what an umpire returns us it returns an umpire Ray with boolean
objects.
So here for the first elements of one is not greater than five.
It gives us a false two is not greater than five false.
And I can see here starting from six we get a true so an umpire returned us and boolean array on the
Ravens US boolean objects and I called this a bully NRA mask ones that we see later what we can do with
it.
Then second we check if each element is less than eight and then we also get back in boolean array so
we can see only the last three elements of our array does not fulfill the condition and gives us the
false and we can also make it more complicated so we can have an and statement on and keywords here
you can check which element fulfills both conditions so is greater than five and less than eight.
So I would assume that the elements sixth and seventh so only two elements fulfill both conditions.
So we are false false false and two times true.
OK.
And we can also take the R operator.
So we check whether at least one condition is met.
So at least the element is either greater than five or either less than eight.
And this holds true for all elements so all elements at least fulfill one condition.
So now what if we want the opposite of let's say our mask re so the opposite array where we have fear
for each element and the opposite.
Boolean value in the air we have to use the terrorism bill so this means uh not are the opposite of
this expression here.
So let's see what we get
so let's check again.
So we took you the opposite of mosque three so the opposite of forces.
True False True False True.
And yeah in the end so we saw here mosque three gets us to truth at Element Six and seven.
And here we get truth and only two false at are the elements six and seven.
And what we cannot do we cannot say.
Instead of having the two the symbol become let's not say not so not does not work in an erect arised
fashion.
And it gives us here the value area.
So the truth value of an array with more than one element is ambiguous.
So not does not work in this case so we have to take here the two the symbol All right so so far we
created a new and the Array method the Boolean value is that shows us whether the elements fulfilled
the condition or not.
And yeah what if we want to filter out the elements which fulfill that condition.
So let's say here a great fire.
So we want to filter out all the elements which are greater than five or six seven eight nine ten.
And we can do this by brilliant indexing.
So we take a and then it's paprika.
We take the condition a create a five and a grade of five as a boolean in the array.
Let's see what happens.
So now num high returns us an array on a slice of array a we had the condition a greater than five is
fulfilled.
So when instead of writing here and spell brackets our condition we can just put in our mask one for
example the condition of mask one is a greater five.
So we already did this here.
So we should get the same result.
So now we want to slice a four hour mask too.
So mask to what this mask to doing.
The condition of mask to us all elements.
Less than eight let's see.
So we get all the elements until seven and mask three it should give us a six and seven.
We already had that.
Yes mask for should give us all elements
so all elements either fulfil the condition one or condition two and mask five through should return
us them the opposite of mask three or so all elements but not Element Six and Seven
back and sit here so six and seven are missing.
All right.
So this is set for boolean indexing and in the next session we will learn about how to create random
numbers with NUM pi.
See you there.